
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0827
 * @Author : WangRuoyu 
 * @Date : 2023/9/16 17:11
 */

#include "iostream"
#include "vector"

using namespace std;

const int N = 1e5 + 10;
int e[N];
int l[N];
int r[N];
int head = 0;
int tail = 1;
int idx = 2;

void init() {
    l[head] = head;
    r[head] = tail;
    l[tail] = head;
    r[tail] = tail;
}


void insertLeft(int x) {
    e[idx] = x;
    r[idx] = r[head];
    l[idx] = head;
    l[r[head]] = idx;
    r[head] = idx++;
}

void insertRight(int x) {
    e[idx] = x;
    l[idx] = l[tail];
    r[idx] = tail;
    r[l[tail]] = idx;
    l[tail] = idx++;
}

void deleteK(int k) {
    l[r[k]] = l[k];
    r[l[k]] = r[k];
}

void insertKLeft(int k, int x) {
    e[idx] = x;
    l[idx] = l[k];
    r[idx] = k;
    r[l[k]] = idx;
    l[k] = idx++;
}

void insertKRight(int k, int x) {
    e[idx] = x;
    r[idx] = r[k];
    l[idx] = k;
    l[r[k]] = idx;
    r[k] = idx++;
}

int main() {
    int n;
    scanf("%d", &n);
    init();
    while (n--) {
        string op;
        cin >> op;
        int k, x;
        if (op == "L") {
            scanf("%d", &x);
            insertLeft(x);
        } else if (op == "R") {
            scanf("%d", &x);
            insertRight(x);
        } else if (op == "D") {
            scanf("%d", &k);
            deleteK(k + 1);
        } else if (op == "IL") {
            scanf("%d %d", &k, &x);
            insertKLeft(k + 1, x);
        } else if (op == "IR") {
            scanf("%d %d", &k, &x);
            insertKRight(k + 1, x);
        }
    }
    for (int i = r[head]; i != tail; i = r[i]) {
        printf("%d ", e[i]);
    }
    return 0;
}